﻿using System;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    public partial class FrmModuleDetails : BaseForm
    {
        public FrmModuleDetails(TreeListPlus tree)
        {
            InitializeComponent();
            tabPane.Tree = tree;
        }

        private async void Form_Load(object sender, EventArgs e)
        {
            await tabPane.BindingModelAsync();
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            DialogCancel();
        }

        private void tabPane_PageBinding(object sender, DetailsFormPaneBindingEventArgs e)
        {
            e.Task = async () =>
            {
                switch (e.Current.TabPageName)
                {
                    case nameof(tabBasic):
                        detailsSource.DataSource = await SysModuleService.Instance.SelectByIdAsync(e.Current.Id);
                        break;
                    case nameof(tabHistoryLog):
                        await historyLogGrid1.LoadAsync(nameof(SysModule), e.Current.Id);
                        break;
                }
            };
        }
    }
}